package com.controller;

import com.github.pagehelper.PageHelper;
import com.pojo.User;
import com.service.UserService;
import com.utils.Response;
import com.utils.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api")
public class TeacherAdminController extends BaseController {

    @Autowired
    UserService userService;

    private static ArrayList<User> users = new ArrayList<>();
    static {
        users.add(new User(1,"a","student"));
        users.add(new User(2,"a","student"));
        users.add(new User(3,"a","student"));
        users.add(new User(4,"a","student"));
        users.add(new User(5,"a","student"));
    }

    @RequestMapping("/list")
    public Response list() {
        ArrayList<User> users = new ArrayList<>();
        users.add(new User(1,"a","student"));
        users.add(new User(2,"a","student"));
        users.add(new User(3,"a","student"));
        users.add(new User(4,"a","student"));
        users.add(new User(5,"a","student"));
//      int i = 1/0;
        List<User> list = userService.list();
        return Response.success().data("items", list).message("获取用户列表成功");
    }



    @RequestMapping("/users")
    public Response Userlist(){
        List<User> list = userService.queryAll();
        list.forEach(System.out::println);
        return Response.success().data("userLists",list).data("users",users).message("获取用户列表成功");
    }


    @RequestMapping("/{id}")
    public Response queryUser(@PathVariable("id") Integer id){
        User user = userService.queryOne(id);
        return Response.success().data("user",user).message("查找成功");
    }

    @RequestMapping("/pageList")
    public Response queryList(){
//      PageHelper.startPage(-1,3);
        startPage();
        List<User> users = userService.queryAll();
        users.forEach(System.out::println);
        return Response.success().data("user",users).message("查找成功");
    }

}